import { useDescriptionsType } from '@/components/DescriptionsType';
import { useContext } from 'react';
import { ConractControllerContext } from '../common';
import { getColorTextLoadMap, getFileNameByPath } from '@/utils';
import { EyeOutlined } from '@ant-design/icons';

interface IGetTaskDescConfigOA {
  onNtkoReadWord: (url: string, urlObj: Record<string, any>, onlyRead?: boolean) => void;
}

const getTaskDescConfigOA = ({ onNtkoReadWord }: IGetTaskDescConfigOA) => {
  const { pageType, contractForm, contractDetailInfo } = useContext(ConractControllerContext);

  let configShemas: any = [
    {
      key: 'contract-task-oa',
      title: '',
      fieldChildren: [
        {
          field: `contractNameOA`,
          label: `合同名称`,
          component: 'Input',
          placeholder: '--',
          disabled: true,
        },
        {
          field: `businessTypeNameOA`,
          label: `合同类型`,
          component: 'Render',
          placeholder: '--',
          render: (text) => {
            const { colorText } = getColorTextLoadMap(text);
            return <span style={{ cursor: 'no-drop' }}>{colorText || '--'}</span>;
          },
        },
        {
          field: `ownDepartmentNameOA`,
          label: `申请部门`,
          component: 'Input',
          disabled: true,
          placeholder: '--',
        },
        {
          field: `ownerNameOA`,
          label: `申请人`,
          component: 'Input',
          placeholder: '--',
          disabled: true,
        },
        {
          field: `busiDepartmentNameOA`,
          label: `业务归口部门`,
          component: 'Input',
          disabled: true,
          placeholder: '--',
        },
        {
          field: `relateDepartmentNameOA`,
          label: `相关部门`,
          component: 'Input',
          disabled: true,
          placeholder: '--',
        },
        {
          field: `sumInTaxOA`,
          label: `合同金额`,
          component: 'InputNumber',
          placeholder: '--',
          disabled: true,
          min: 0,
          contentAfter: '元',
          step: '0.01',
        },
        {
          field: `projectNameOA`,
          label: `资金来源`,
          component: 'Input',
          placeholder: '--',
          disabled: true,
        },
        {
          field: `procureRealNameOA`,
          label: `采购方式`,
          component: 'Input',
          disabled: true,
          placeholder: '--',
        },
        {
          field: `bidTimeOA`,
          label: `中标时间`,
          component: 'DatePicker',
          format: 'YYYY-MM-DD',
          placeholder: '--',
          disabled: true,
        },
        {
          field: `oppositeNameOA`,
          label: `单位名称`,
          component: 'Input',
          disabled: true,
          placeholder: '--',
        },
        {
          field: `contractURLOA`,
          label: `合同文本`,
          component: 'Render',
          slotRender: (text: any) => {
            const contractName = text ? getFileNameByPath(text) : '';
            return (
              <div style={{ width: '100%', display: 'flex', justifyContent: 'space-between', padding: 10 }}>
                {contractName ? (
                  <>
                    <a>{contractName}</a>
                    <a
                      onClick={() => {
                        onNtkoReadWord('contractURL', contractDetailInfo, true);
                      }}
                    >
                      <EyeOutlined />
                    </a>
                  </>
                ) : (
                  <span>--</span>
                )}
              </div>
            );
          },
        },
      ],
    },
  ];

  /** 表单配置 */
  const [config, methods] = useDescriptionsType({
    labelWidth: 190,
    basicForm: contractForm,
    name: 'contract-taskOA-form',
    schemas: configShemas,
  });

  return {
    config,
    methods,
  };
};

export { getTaskDescConfigOA };
